package com.kfm.spring.controller;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
public class ExHandler {

    @ExceptionHandler(RuntimeException.class)
    public ModelAndView exceptionHandler(Exception e) {
        ModelAndView mv = new ModelAndView("error");
        mv.addObject("msg", e.getMessage());
        return mv;
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public String ex(Exception e) {
       return "出错了";
    }




}
